package com.sn.pw.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.ChainQuery;
import com.sn.pw.code.ErrorMsg;
import com.sn.pw.dao.entity.Bidding;
import com.sn.pw.dao.entity.ShipOrder;
import com.sn.pw.dao.entity.User;
import com.sn.pw.dao.mapper.BiddingMapper;
import com.sn.pw.service.BiddingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sn.pw.service.OrderService;
import com.sn.pw.service.UserService;
import com.sn.pw.vo.resp.*;
import com.sn.pw.vo.createreq.BiddingCreateReq;
import com.sn.pw.vo.updatereq.BiddingUpdateReq;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.bean.BeanUtil;
import com.sn.pw.page.PageReq;
import com.sn.pw.page.PageResp;
import com.sn.pw.page.ConventPage;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sn.pw.exception.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;

import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 竞价表 服务实现类
 * </p>
 *
 * @author mx
 * @since 2023-12-07
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class BiddingServiceImpl extends ServiceImpl<BiddingMapper, Bidding> implements BiddingService {
    private final OrderService orderService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean create(BiddingCreateReq param){
        return super.save(BeanUtil.toBean(param, Bidding.class));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(Long id){
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(List<Long> ids) {
    return super.removeBatchByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean update(BiddingUpdateReq param){
        return super.updateById(BeanUtil.toBean(param, Bidding.class));
    }

    @Override
    public BiddingResp findById(Long id){
        Bidding info = super.getById(id);
        if(ObjectUtil.isEmpty(info)){
            throw new ServiceException(ErrorMsg.DATA_NOT_EXIST);
        }
        return BeanUtil.toBean(info, BiddingResp.class);
    }

    @Override
    public List<BiddingResp> findList(List<Long> ids){
        LambdaQueryWrapper<Bidding> lambdaQueryWrapper = Wrappers.<Bidding>lambdaQuery().in(Bidding::getId, ids);
        List<Bidding> list = super.list(lambdaQueryWrapper);
        return BeanUtil.copyToList(list,BiddingResp.class);
    }

}
